home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 46.0 KB | 1,393 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWMAObjs.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //========================================================================================
-
- #ifndef FWMAOBJS_H
- #include "FWMAObjs.h"
- #endif
-
- #ifndef FWSVIEW_H
- #include "FWSView.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWSTATIC_H
- #include "FWStatic.h"
- #endif
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- #ifndef FWPOPUP_H
- #include "FWPopup.h"
- #endif
-
- #ifndef FWLISTBX_H
- #include "FWListBx.h"
- #endif
-
- #ifndef FWCLUSTR_H
- #include "FWClustr.h"
- #endif
-
- #ifndef FWTABBER_H
- #include "FWTabber.h"
- #endif
-
- #ifndef FWUNKNOW_H
- #include "FWUnknow.h"
- #endif
-
- #ifndef FWPICTSV_H
- #include "FWPictSv.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWRANSIN_H
- #include "FWRanSin.h"
- #endif
-
- //========================================================================================
- // MacApp types and constants
- //========================================================================================
-
- typedef unsigned short WindowFlags;
-
- const long mOKHit = 1;
- const long mCancelHit = 2;
- const long mButtonHit = 3;
- const long mCheckBoxHit = 4;
- const long mClusterHit = 5;
- const long mEditTextHit = 6;
- const long mIconHit = 7;
- const long mListItemHit = 8;
- const long mListScrollBarHit = 9;
- const long mPictureHit = 10;
- const long mPopupHit = 11;
- const long mRadioHit = 12;
- const long mStaticTextHit = 13;
- const long mHScrollBarHit = 14;
- const long mVScrollBarHit = 15;
-
- //========================================================================================
- //
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwmacapp
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CMAObject::FW_CMAObject
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject::FW_CMAObject(ResType type) :
- fClassID(type),
- fEndOfObject(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAObject::ReadFrom
- //----------------------------------------------------------------------------------------
-
- void FW_CMAObject::ReadFrom(Environment* ev, FW_CReadableStream& stream,
- FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(ev);
- FW_UNUSED(stream);
- FW_UNUSED(superview);
- FW_UNUSED(receiver);
- // nothing to do for ODF
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMABehavior::FW_CMABehavior
- //----------------------------------------------------------------------------------------
-
- FW_CMABehavior::FW_CMABehavior(ResType type) :
- FW_CMAObject(type)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMABehavior::ReadFrom
- //----------------------------------------------------------------------------------------
-
- void FW_CMABehavior::ReadFrom(Environment* ev, FW_CReadableStream& stream,
- FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- inherited::ReadFrom(ev, stream, superview, receiver);
-
- ResType identifier;
- Boolean enabled;
- long idleFreq;
-
- stream >> identifier >> enabled >> idleFreq; // ignored by ODF
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMADialogBehavior::FW_CMADialogBehavior
- //----------------------------------------------------------------------------------------
-
- FW_CMADialogBehavior::FW_CMADialogBehavior(ResType type) :
- FW_CMABehavior(type)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMADialogBehavior::ReadFrom
- //----------------------------------------------------------------------------------------
-
- void FW_CMADialogBehavior::ReadFrom(Environment* ev, FW_CReadableStream& stream,
- FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- inherited::ReadFrom(ev, stream, superview, receiver);
-
- // Read TDialogBehavior fields:
- // - the OK and Cancel button ids will be used when creating buttons in this window.
- // - the modal field is ignored since the creation of the ODF dialog is done by program
- Boolean modal;
-
- stream >> modal;
- stream >> FW_CMacAppReader::gDefaultButtonID;
- stream >> FW_CMacAppReader::gCancelButtonID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMADialogBehavior::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMADialogBehavior::Create(ResType type)
- {
- return new FW_CMADialogBehavior(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAEventHandler::FW_CMAEventHandler
- //----------------------------------------------------------------------------------------
-
- FW_CMAEventHandler::FW_CMAEventHandler(ResType type) :
- FW_CMAObject(type)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAEventHandler::ReadFrom
- //----------------------------------------------------------------------------------------
- // [LSD] this should never be called directly from FW_CMacAppReader::ReadStreamObject, right?
- // Pure EventHandler objects are not persistent, right?
-
- void FW_CMAEventHandler::ReadFrom(Environment* ev, FW_CReadableStream& stream,
- FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- inherited::ReadFrom(ev, stream, superview, receiver);
-
- // Read in TEventHandler fields
- long idleFreq;
-
- stream >> fIdentifier >> fEnabled >> idleFreq;
-
- short numBehaviors;
- stream >> numBehaviors;
-
- for (short count = 0; count < numBehaviors; ++count)
- {
- // OFD only uses TDialogBehavior objects for now
- FW_CMacAppReader::ReadStreamObject(ev, stream, superview, receiver,
- FW_CMacAppReader::kBehavior);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAView::FW_CMAView
- //----------------------------------------------------------------------------------------
-
- FW_CMAView::FW_CMAView(ResType type) :
- FW_CMAEventHandler(type),
- fIsContentView(false),
- // fScrollingDirection(FW_kNoScrolling),
- fIsScroller(false)
- {
- // If gScroller is not null this is the first view following TScroller in the stream
- if (FW_CMacAppReader::gScroller != 0)
- fIsContentView = true;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAView::ReadFrom
- //----------------------------------------------------------------------------------------
- // Main entry point for reading MacApp view resources.
- // It's much more complex than the original MacApp ReadFrom method because of all the
- // work-arounds necessary to map MacApp views to ODF views, especially when dealing
- // with unregistered classes, scrollers and clusters.
-
- void FW_CMAView::ReadFrom(Environment* ev, FW_CReadableStream& stream,
- FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_ASSERT(superview);
- FW_ASSERT(fIsScroller == false || FW_CMacAppReader::gScroller != 0);
-
- FW_TRY
- {
- inherited::ReadFrom(ev, stream, superview, receiver); // read in TEventHandler info
-
- // Read MacApp fields for each class
- ReadFields(ev, stream);
-
- // Create the ODF view corresponding to the MacApp view.
- // New controls will also be linked to the supplied receiver (if not null)
- FW_CView* newView = CreateODFView(ev, superview, receiver);
-
- // Save the current globale offset and update it with the current view location
- // in case the MacApp view is not translated into and ODF view (cases of TScroller
- // TCluster, TView,...)
- FW_CPoint currentOffset = FW_CMacAppReader::gOffset;
- if (newView == superview)
- FW_CMacAppReader::gOffset += fBounds.TopLeft();
- else
- FW_CMacAppReader::gOffset = FW_kZeroPoint;
-
- // In case we are reading an unknown view class we need to skip the rest of
- // the object data at this point (including subviews... too bad)
- if (fEndOfObject != 0)
- {
- ((FW_ORandomAccessSink *)stream.GetSink())->SetPosition(ev, fEndOfObject);
-
- // If the unknown view was the scroller's subview we do take the time to
- // make it the content view and create an ODF ScrollBarScroller
- PostCreateODFView(ev, (FW_CSuperView*)newView);
- }
- else
- {
- short numSubViews;
- stream >> numSubViews;
-
- if (numSubViews > 0)
- {
- // This first part is a big workaround to deal with MacApp views which don't
- // map to ODF superviews, like radio clusters and list boxes.
- // MacApp clusters contain subviews, but ODF FW_CGroupBox is just a decoration,
- // not a superview, so we cannot create nested subviews.
- // We must:
- // - Use the same superview instead of newView
- // - Set gOffset to the groupBox location
- // - Keep track of the current FW_CRadioCluster to link radio buttons
- // - Deal with nested clusters ...
-
- FW_CRadioCluster* currentCluster = 0;
-
- FW_CSuperView* newSuperview = FW_DYNAMIC_CAST(FW_CSuperView, newView);
- if(newSuperview == 0)
- {
- newSuperview = superview;
-
- // If we just created a GroupBox it's because we read a MacApp cluster.
- // We now create an ODF RadioCluster to be used by nested radio buttons
- // but we must also save the current cluster to handle nested clusters!
-
- if (fClassID == kStdCluster)
- {
- currentCluster = FW_CMacAppReader::gCluster;
- FW_CMacAppReader::gCluster = FW_NEW(FW_CRadioCluster, (ev));
-
- FW_CMacAppReader::gOffset = currentOffset + fBounds.TopLeft();
- }
- }
- else if (newSuperview == superview && FW_CMacAppReader::gScroller != 0 &&
- fIsContentView == true)
- {
- // Handle cases where a scroller contains a dialog view
- MACAPP_WARNING("MacAppReader Warning: Scroller's subview cannot be mapped to ODF content view");
- FW_CMacAppReader::gScroller = 0;
- }
- else
- {
- // Declare the content view and create the ODF scroller if necessary
- PostCreateODFView(ev, newSuperview);
- }
-
- // Read subviews recursively in the MacApp stream
- for (short count = 0; count < numSubViews; ++count)
- {
- FW_CMacAppReader::ReadStreamObject(ev, stream, newSuperview,
- receiver, FW_CMacAppReader::kView);
- }
-
- // Delete empty clusters (rare case where no radio buttons were added)
- if(FW_CMacAppReader::gCluster != 0 &&
- FW_CMacAppReader::gCluster->GetButtonOn(ev) == 0)
- delete FW_CMacAppReader::gCluster;
-
- // Restore the previous cluster
- FW_CMacAppReader::gCluster = currentCluster;
- }
-
- if (fIsScroller == true && FW_CMacAppReader::gScroller != 0)
- {
- // If we get here it means that the TScroller didn't contain any subview
- // or that its subview wasn't one of the views supporting scrolling in ODF,
- // i.e. not a scrolling content view or not a list-box
- // (Note: we avoid this error for TTEView with a scroller)
- MACAPP_WARNING("MacAppReader Warning: Scroller's subview is missing or doesn't support scrolling in ODF");
-
- FW_CMacAppReader::gScroller = 0;
- }
- }
-
- // Restore the previous offset
- FW_CMacAppReader::gOffset = currentOffset;
-
- delete this; // We don't need our factory object anymore
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete this;
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAView::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAView::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- short templateVersion;
- VPoint itsLocation, itsSize;
- Byte itsHSizeDet, itsVSizeDet;
- Boolean handlesCursor, letsSubViewsHandleCursor;
- Boolean handlesHelp, letsSubViewsHandleHelp;
- short helpID, helpIndex, cursorID;
- long userArea;
- ResType dummyID;
-
- // Read TView fields
-
- stream >> templateVersion; // ignored by ODF
- stream.Read(&itsLocation, sizeof(VPoint));
- stream.Read(&itsSize, sizeof(VPoint));
- stream >> itsHSizeDet >> itsVSizeDet; // ignored by ODF
- stream >> fVisible >> fWantsToBeTarget;
- stream >> handlesCursor >> letsSubViewsHandleCursor; // ignored by ODF
- stream >> cursorID; // ignored by ODF
- stream >> handlesHelp >> letsSubViewsHandleHelp; // ignored by ODF
- stream >> helpID >> helpIndex; // ignored by ODF
-
- // Drawing environment and adorners are ignored by ODF
- FW_CMacAppReader::ReadStreamObject(ev, stream, 0, 0, FW_CMacAppReader::kDrawingEnv);
- FW_CMacAppReader::ReadStreamObject(ev, stream, 0, 0, FW_CMacAppReader::kAdorner);
-
- stream >> userArea; // ignored by ODF
- stream >> dummyID; // ignored by ODF
-
- // ODF doesn't support 32 bit coordinates yet...
- if (itsLocation.h > FW_MAXINT16 || itsLocation.h < FW_MININT16 ||
- itsLocation.v > FW_MAXINT16 || itsLocation.v < FW_MININT16 ||
- itsSize.h > FW_MAXINT16 || itsSize.v > FW_MAXINT16)
- MACAPP_WARNING("MacAppReader Warning: Found a view out of 16 bit space. ODF will adjust its bounds.");
-
- // Manual corrections. This will make it easier to spot the offending views
- if (itsLocation.h > FW_MAXINT16)
- itsLocation.h = 0;
- if (itsLocation.h < FW_MININT16)
- itsLocation.h = 0;
- if (itsLocation.v > FW_MAXINT16)
- itsLocation.v = 0;
- if (itsLocation.v < FW_MININT16)
- itsLocation.v = 0;
- if (itsSize.h > FW_MAXINT16)
- itsSize.h = FW_MAXINT16 / 2;
- if (itsSize.v > FW_MAXINT16)
- itsSize.v = FW_MAXINT16 / 2;
-
- fExtent.Set(FW_IntToFixed(itsSize.h), FW_IntToFixed(itsSize.v));
-
- // If there is a scroller this is the first subview read after the scroller so
- // it must be the scrolling view. We adjust its bounds to scroller's bounds
- if (FW_CMacAppReader::gScroller != 0 && fIsScroller == false)
- {
- fBounds = FW_CMacAppReader::gScroller->fBounds;
- // fBounds.left += FW_kFixedPos1;
- // fBounds.top += FW_kFixedPos1;
-
- // fBindings = FW_CMacAppReader::gScroller->fBindings;
- }
- else
- {
- // The view location takes the current cluster offset into account
- FW_CPoint topLeft(FW_IntToFixed(itsLocation.h), FW_IntToFixed(itsLocation.v));
- fBounds.Set(topLeft+FW_CMacAppReader::gOffset, fExtent.x, fExtent.y);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAView::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAView::Create(ResType type)
- {
- return new FW_CMAView(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAView::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAView::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(ev);
- FW_UNUSED(receiver);
- // We don't create any ODF view for a TView, we just return the same superview to be
- // propagated to the subviews in FW_CMAView::ReadFrom.
-
- // Note: There should be only 2 cases where the MacApp stream contains a TView:
- // - At the top level, when the root was created as TView instead of TWindow
- // - When declaring a listbox (TView with a TScroller with a TTextListView) see Form.
-
- return superview;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAView::PostCreateODFView
- //----------------------------------------------------------------------------------------
-
- void FW_CMAView::PostCreateODFView(Environment* ev, FW_CSuperView* view)
- {
- // This method is used to declare the frame's content view and create the
- // associated ODF scroller and its scroll bars.
-
- if (fIsContentView == true && FW_CMacAppReader::gScroller != 0)
- {
- // Since we may get here because an unknown TView was found in the stream
- // we do an extra check to make sure we have created the content view yet.
-
- FW_CFrame* frame = view->GetFrame(ev);
- if (frame->IsContentView(ev))
- {
- FW_CMAScrollBarScroller* scroller = FW_CMacAppReader::gScroller;
-
- // Declare the content view (will fail if it's not the first scroller!)
- view->BecomeContentView(ev);
-
- // Create the scroll bars inside the view's superview.
- // Our convention is to create scroll bars only if their id is not ' '
- // (the MacApp scroller resource doesn't contain this information, scroll bar
- // objects are stored further down the stream)
- FW_CSuperView* superview = view->GetSuperView(ev);
- FW_ASSERT(superview);
-
- FW_CScrollBar* horzSB = 0;
- if (scroller->fHorzSbID != kNullSignature)
- {
- FW_CRect bounds = scroller->fBounds;
- bounds.left += FW_IntToFixed(scroller->fSBarOffsets.left) - FW_kFixedPos1;
- bounds.right += FW_IntToFixed(scroller->fSBarOffsets.right) + FW_kFixedPos1;
- bounds.top = bounds.bottom;
- bounds.bottom += FW_IntToFixed(16);
-
- horzSB = FW_NEW(FW_CScrollBar, (ev, superview, bounds, scroller->fHorzSbID));
- }
-
- FW_CScrollBar* vertSB = 0;
- if (scroller->fVertSbID != kNullSignature)
- {
- FW_CRect bounds = scroller->fBounds;
- bounds.top += FW_IntToFixed(scroller->fSBarOffsets.top) - FW_kFixedPos1;
- bounds.bottom += FW_IntToFixed(scroller->fSBarOffsets.bottom) + FW_kFixedPos1;
- bounds.left = bounds.right;
- bounds.right += FW_IntToFixed(16);
-
- vertSB = FW_NEW(FW_CScrollBar, (ev, superview, bounds, scroller->fVertSbID));
- }
-
- // Create the scroller and declare it to the frame
- FW_CFrame* frame = view->GetFrame(ev);
- scroller->fODFScroller = FW_NEW(FW_CScrollBarScroller,
- (ev, frame, scroller->fLiveScrolling, horzSB, vertSB));
-
- frame->AdoptScroller(ev, scroller->fODFScroller);
- }
-
- // Reset the globale to show that we used the scroller
- // (FW_CMAScrollBarScroller object itself will be deleted when returning from
- // FW_CMAView::ReadFrom like all MacApp objects)
- FW_CMacAppReader::gScroller = 0;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAWindow::FW_CMAWindow
- //----------------------------------------------------------------------------------------
-
- FW_CMAWindow::FW_CMAWindow(ResType type) :
- FW_CMAView(type)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAWindow::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAWindow::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in TWindow fields
- ResType targetID;
- WindowFlags itsFlags;
- short strListID, index;
-
- stream >> fProcID >> targetID;
- stream >> itsFlags;
- stream >> strListID >> index;
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAWindow::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAWindow::Create(ResType type)
- {
- return new FW_CMAWindow(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAWindow::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAWindow::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- // Set root frame's window size and location
- FW_CFrame* frame = superview->GetFrame(ev);
- if (frame->IsRoot(ev))
- {
- // For MacApp fBounds is the position of the window content, not its frame
- // so we must offset by the title bar height
- FW_CWindow* win = frame->GetWindow(ev);
- fBounds.Offset(FW_kFixed0, -FW_IntToFixed(18));
- win->SetWindowPosition(ev, fBounds.TopLeft());
- win->SetWindowSize(ev, fBounds.Size());
-
- // Add a grow box when the MacApp window has one
- if ((fProcID & 0x000F) == documentProc)
- {
- // Grow box location is hard-coded to bottom right corner of frame
- // View id is hard-coded to 'grow' (non-root frames need to remove it)
- FW_CPoint loc = frame->GetSize(ev);
- loc.x -= FW_IntToFixed(15);
- loc.y -= FW_IntToFixed(15);
- FW_CGrowBox* growBox = new FW_CGrowBox(ev, frame, 'grow', loc);
- }
- }
-
-
- // We don't create any ODF view for a TWindow, just return superview to be
- // propagated to the subviews in FW_CMAView::ReadFrom.
- // But we need to reset fBounds to 0 to avoid changing FW_CMacAppReader::gOffset
- fBounds.Place(FW_kFixed0, FW_kFixed0);
-
- return superview;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMADialog::FW_CMADialog
- //----------------------------------------------------------------------------------------
-
- FW_CMADialog::FW_CMADialog(ResType type) :
- FW_CMAView(type)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMADialog::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMADialog::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read OK and Cancel button ids.
- stream >> FW_CMacAppReader::gDefaultButtonID;
- stream >> FW_CMacAppReader::gCancelButtonID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMADialog::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMADialog::Create(ResType type)
- {
- return new FW_CMADialog(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMADialog::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMADialog::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(ev);
- FW_UNUSED(receiver);
- // we don't create any ODF view for a TDialog, just return superview to be
- // propagated to the subviews in FW_CMAView::ReadFrom
- return superview;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAStaticText::FW_CMAStaticText
- //----------------------------------------------------------------------------------------
-
- FW_CMAStaticText::FW_CMAStaticText(ResType type) :
- FW_CMAControl(type)
- {
- // A static text cannot be the content view
- fIsContentView = false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAStaticText::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAStaticText::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in Static Text fields
- Boolean eraseFirst;
- short strListID, index, justitication;
-
- stream >> fAutoWrap >> eraseFirst;
- stream >> justitication;
- stream >> strListID >> index;
-
- if (strListID != -1) // retrieve the text from a STR# resource
- ::GetIndString(fText, strListID, index);
- else
- fText[0] = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAStaticText::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAStaticText::Create(ResType type)
- {
- return new FW_CMAStaticText(type);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CMAStaticText::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAStaticText::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- FW_CFont font;
- FW_CColor color;
- FW_CMacAppReader::GetTextStyle(fTextStyleID, font, color);
- FW_TextBoxOptions options = FW_kTextBoxClipToBox;
- if (fAutoWrap)
- options |= FW_kTextBoxWordWrap;
- FW_CString text((char *)&fText[1], (FW_ByteCount)fText[0]);
- FW_CInk textInk(color, FW_kRGBWhite, FW_kOr);
-
- FW_CStaticText* view = FW_NEW(FW_CStaticText, (ev, superview, fBounds, fIdentifier, text, font,
- options, textInk));
- // view->SetBindings(ev, fBindings);
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAEditText::FW_CMAEditText
- //----------------------------------------------------------------------------------------
-
- FW_CMAEditText::FW_CMAEditText(ResType type) :
- FW_CMAStaticText(type)
- {
- // A TEditText cannot be the content view
- fIsContentView = false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAEditText::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAEditText::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in TEditText fields
- long controlChars;
-
- stream >> fMaxChars;
- stream >> controlChars; // ignored by ODF
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAEditText::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAEditText::Create(ResType type)
- {
- return new FW_CMAEditText(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAEditText::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAEditText::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- FW_CFont font;
- FW_CColor color;
- FW_CMacAppReader::GetTextStyle(fTextStyleID, font, color);
- FW_CString text((char *)&fText[1], (FW_ByteCount)fText[0]);
-
- unsigned short attributes = FW_CEditView::kDrawBox + FW_CEditView::kAutoScroll;
- if (fAutoWrap)
- attributes += FW_CEditView::kWordWrap;
-
- FW_CEditView* view = FW_NEW(FW_CEditView, (ev, superview, fBounds, fIdentifier, text,
- font, fMaxChars, attributes));
- // view->SetBindings(ev, fBindings);
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATEView::FW_CMATEView
- //----------------------------------------------------------------------------------------
-
- FW_CMATEView::FW_CMATEView(ResType type) :
- FW_CMAView(type)
- {
- // A TTEView cannot be the content view
- fIsContentView = false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATEView::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMATEView::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in TTEView fields
- Boolean styleType, acceptsChanges, freeText, preferOutline;
- long commandNumber;
- VRect inset;
- short justification;
-
- stream >> styleType >> fAutoWrap;
- stream >> acceptsChanges >> freeText; // ignored by ODF
- stream >> commandNumber; // ignored by ODF
- stream >> fMaxChars;
- stream.Read(&inset, sizeof(VRect)); // ignored by ODF
- stream >> justification; // ignored by ODF
- stream >> fTextStyleID;
- stream >> preferOutline;
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATEView::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMATEView::Create(ResType type)
- {
- return new FW_CMATEView(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATEView::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMATEView::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- FW_CFont font;
- FW_CColor color;
- FW_CMacAppReader::GetTextStyle(fTextStyleID, font, color);
- FW_CString text("");
-
- unsigned short attributes = FW_CEditView::kDrawBox + FW_CEditView::kAutoScroll;
- if (fAutoWrap)
- attributes += FW_CEditView::kWordWrap;
-
- FW_CEditView* view = FW_NEW(FW_CEditView, (ev, superview, fBounds, fIdentifier, text,
- font, fMaxChars, attributes));
- // view->SetBindings(ev, fBindings);
-
- // Reset the scroller global to 0 to "pretend" that we used it
- // (if we don't do it we'll get an ASSERT in ReadFrom)
- FW_CMacAppReader::gScroller = 0;
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMACluster::FW_CMACluster
- //----------------------------------------------------------------------------------------
-
- FW_CMACluster::FW_CMACluster(ResType type) :
- FW_CMAControl(type)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMACluster::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMACluster::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in Cluster fields
- short strListID, index;
-
- stream >> strListID >> index;
-
- if (strListID != -1) // retrieve the label from a STR# resource
- ::GetIndString(fLabel, strListID, index);
- else
- fLabel[0] = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMACluster::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMACluster::Create(ResType type)
- {
- return new FW_CMACluster(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMACluster::CreateODFView
- //----------------------------------------------------------------------------------------
- // MacApp's TCluster combines ODF GroupBox and RadioCluster objects. We only create the
- // FW_CGroupBox here. See hack in FW_CMAView::ReadFrom to handle RadioClusters...
-
- FW_CView* FW_CMACluster::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- FW_CFont font;
- FW_CColor color;
- FW_CMacAppReader::GetTextStyle(fTextStyleID, font, color);
-
- FW_TextBoxOptions options = FW_kTextBoxClipToBox | FW_kTextBoxWordWrap;
- FW_CString label((char *)&fLabel[1], (FW_ByteCount)fLabel[0]);
- FW_CInk textInk(color, FW_kRGBWhite, FW_kOr);
-
- FW_CGroupBox* view = FW_NEW(FW_CGroupBox, (ev, superview, fBounds, fIdentifier, label, font,
- options, textInk, color));
- // view->SetBindings(ev, fBindings);
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAControl::FW_CMAControl
- //----------------------------------------------------------------------------------------
-
- FW_CMAControl::FW_CMAControl(ResType type) :
- FW_CMAView(type),
- fTextStyleID(-1)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAControl::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAControl::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read TControl fields
-
- Boolean hiliteState, dimState, sizeable;
- VRect itsInset;
- Boolean preferOutline;
-
- stream >> fEventNumber;
- stream >> hiliteState >> dimState >> sizeable; // ignored by ODF
- stream.Read(&itsInset, sizeof(VRect)); // ignored by ODF
- stream >> fTextStyleID;
- stream >> preferOutline; // ignored by ODF
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAControl::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAControl::Create(ResType type)
- {
- return new FW_CMAControl(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAControl::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAControl::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- // A MacApp TControl cannot be mapped to the pure virtual ODF FW_CControl
- // so we create a FW_CUnknownView instead
- FW_CString name((char*)&fClassID, 4);
- FW_CUnknownView* view = FW_NEW(FW_CUnknownView, (ev, superview, fIdentifier, fBounds, name));
-
- // view->SetBindings(ev, fBindings);
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAButton::FW_CMAButton
- //----------------------------------------------------------------------------------------
-
- FW_CMAButton::FW_CMAButton(ResType type) :
- FW_CMAControl(type),
- fIsOn(0)
- {
- // A button cannot be the content view
- fIsContentView = false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAButton::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAButton::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Combines TButton, TCheckBox and TRadio fields here
-
- short strListID, index;
-
- if (fClassID == kStdButton)
- {
- fKind = FW_kPushButton;
- }
- else
- {
- stream >> fIsOn; // only for TRadio and TCheckBox
- if (fClassID == kStdCheckBox)
- fKind = FW_kCheckButton;
- else
- fKind = FW_kRadioButton;
- }
-
- stream >> strListID >> index;
-
- if (strListID != -1) // retrieve the buttons's label from a STR# resource
- ::GetIndString(fLabel, strListID, index);
- else
- fLabel[0] = 0;
-
- // Convert all MacApp default button events to the ODF default FW_kButtonPressedMsg
-
- if (fEventNumber == mButtonHit || fEventNumber == mCheckBoxHit || fEventNumber == mRadioHit)
- fEventNumber = FW_kButtonPressedMsg;
-
- // Special case of default and cancel buttons in dialogs
-
- if (FW_CMacAppReader::gDefaultButtonID != 0 &&
- FW_CMacAppReader::gDefaultButtonID == fIdentifier &&
- fKind == FW_kPushButton)
- {
- fKind = FW_kDefaultPushButton;
- fEventNumber = FW_kDefaultButtonMsg;
- FW_CMacAppReader::gDefaultButtonID = 0;
- }
- if (FW_CMacAppReader::gCancelButtonID != 0 &&
- FW_CMacAppReader::gCancelButtonID == fIdentifier &&
- fKind == FW_kPushButton)
- {
- fEventNumber = FW_kCancelButtonMsg;
- FW_CMacAppReader::gCancelButtonID = 0;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAButton::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAButton::Create(ResType type)
- {
- return new FW_CMAButton(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAButton::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAButton::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_CFont font;
- FW_CColor color;
- FW_CMacAppReader::GetTextStyle(fTextStyleID, font, color);
-
- FW_ControlValue value = fIsOn ? 1 : 0;
- FW_CString label((char *)&fLabel[1], (FW_ByteCount)fLabel[0]);
-
- FW_CButton* view = FW_NEW(FW_CButton,
- (ev, superview, fBounds, fIdentifier, fKind, label, font, fEventNumber, value));
- // view->SetBindings(ev, fBindings);
-
- // Connect our new button to the supplied receiver
- if (receiver)
- view->LinkControlTo(ev, receiver);
-
- // Radio buttons are usually connected to clusters too
- if (fKind == FW_kRadioButton)
- {
- if (FW_CMacAppReader::gCluster == 0)
- {
- // Rare case where there is not Cluster preceding the radio button in the
- // stream. We create one on the fly, it will be used by other radio buttons
- // at the same level of this one.
- FW_CMacAppReader::gCluster = FW_NEW(FW_CRadioCluster, (ev));
- }
- FW_CMacAppReader::gCluster->AddRadio(ev, view);
- }
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPopupMenu::FW_CMAPopupMenu
- //----------------------------------------------------------------------------------------
-
- FW_CMAPopupMenu::FW_CMAPopupMenu(ResType type) :
- FW_CMAControl(type)
- {
- // A popup cannot be the content view
- fIsContentView = false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPopupMenu::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAPopupMenu::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in Popup fields
- short titleJust;
- char titleStyle;
- short strListID, index;
-
- stream >> fMenuID >> fCurrentItem >> fLabelWidth;
- stream >> titleStyle >> titleJust; // not used by ODF
- stream >> fUseAddResMenu >> fUseAddResMenuResType;
- stream >> strListID >> index;
-
- if (strListID != -1) // retrieve the buttons's label from a STR# resource
- ::GetIndString(fLabel, strListID, index);
- else
- fLabel[0] = 0; // ODF doesn't try to get the label from the MenuRef itself
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPopupMenu::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAPopupMenu::Create(ResType type)
- {
- return new FW_CMAPopupMenu(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPopupMenu::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAPopupMenu::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_CFont font;
- FW_CColor color;
- FW_CMacAppReader::GetTextStyle(fTextStyleID, font, color);
- FW_CString label((char *)&fLabel[1], (FW_ByteCount)fLabel[0]);
- FW_PopupMenuStyle popupVariation = fUseAddResMenu ? popupUseAddResMenu : 0;
- long popupRefCon = fUseAddResMenu ? fUseAddResMenuResType : 0;
-
- // MenuID and titleWidth were stored in the MinValue & MaxValue fields of Control
- FW_CPopupMenu* view = FW_NEW(FW_CPopupMenu, (ev, superview, fBounds, fIdentifier,
- fMenuID, label, fLabelWidth, fCurrentItem, popupVariation, font, popupRefCon));
- // view->SetBindings(ev, fBindings);
-
- // Connect our new popup to the supplied receiver
- if (receiver)
- view->LinkControlTo(ev, receiver);
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAScrollBarScroller::FW_CMAScrollBarScroller
- //----------------------------------------------------------------------------------------
-
- FW_CMAScrollBarScroller::FW_CMAScrollBarScroller(ResType type) :
- FW_CMAView(type),
- fODFScroller(0),
- fLiveScrolling(false)
- {
- // Use globale variable also as a flag for the next view in the stream which will
- // be the scrolling view;
- FW_CMacAppReader::gScroller = this;
-
- fIsScroller = true;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAScrollBarScroller::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAScrollBarScroller::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in TScroller fields
- VPoint scrollLimits, scrollUnits;
- Boolean vertConstraint, horzConstraint;
- Boolean respondsToFunctionKeys;
-
- stream >>fVertSbID >> fHorzSbID;
- stream.Read(&scrollLimits, sizeof(VPoint)); // SEE LATER
- stream.Read(&scrollUnits, sizeof(VPoint)); // SEE LATER
- stream >> vertConstraint >> horzConstraint; // not used by ODF
- stream.Read(&fSBarOffsets, sizeof(VRect));
- stream >> respondsToFunctionKeys; // not used by ODF
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAScrollBarScroller::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAScrollBarScroller::Create(ResType type)
- {
- return new FW_CMAScrollBarScroller(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAScrollBarScroller::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAScrollBarScroller::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(ev);
- FW_UNUSED(receiver);
- // We defer the creation of the ODF scroller when we read the next view in the stream,
- // which must be the scrolling view. This allows to handle list boxes.
-
- return superview;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATextGridView::FW_CMATextGridView
- //----------------------------------------------------------------------------------------
-
- FW_CMATextGridView::FW_CMATextGridView(ResType type) :
- FW_CMAView(type)
- {
- // A TTextGridView cannot be the content view
- fIsContentView = false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATextGridView::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMATextGridView::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // We read first the TGridView fields since FW_CMATextGridView derives from FW_MAView
- // (no need to use a FW_CMAGridView class until ODF supports multi-column lists)
-
- short numOfCols, rowHeight, colWidth, rowInset, colInset;
- Boolean adornRows, adornCols;
-
- stream >> fNumOfRows;
- stream >> numOfCols; // ignored by ODF
- stream >> rowHeight >> colWidth >> rowInset >> colInset; // ignored by ODF
- stream >> adornRows >> adornCols; // ignored by ODF
- stream >> fSingleSelection;
-
- // Read now the TTextGridView fields
-
- Boolean preferOutlineFont;
-
- stream >> fTextStyleID;
- stream >> preferOutlineFont; // ignored by ODF
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATextGridView::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMATextGridView::Create(ResType type)
- {
- return new FW_CMATextGridView(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMATextGridView::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMATextGridView::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- FW_CFont font;
- FW_CColor color;
- FW_CMacAppReader::GetTextStyle(fTextStyleID, font, color);
-
- // Adjust fBounds to include the vertical scrollbar
- fBounds.right += FW_IntToFixed(16);
-
- // Create the ODF listbox
- // (vertical SB, dbl-click message and focus frame are hard coded)
- FW_CListBox* view = FW_NEW(FW_CListBox, (ev, superview, fBounds, fIdentifier, fNumOfRows,
- true, font, FW_kListBoxDoubleClickedMsg, fSingleSelection, true, false));
- // view->SetBindings(ev, fBindings);
-
- // Reset the scroller globale to 0 to show that we used it
- FW_CMacAppReader::gScroller = 0;
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPictSView::FW_CMAPictSView
- //----------------------------------------------------------------------------------------
-
- FW_CMAPictSView::FW_CMAPictSView(ResType type) :
- FW_CMAControl(type),
- fPictID(-1)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPictSView::ReadFields
- //----------------------------------------------------------------------------------------
-
- void FW_CMAPictSView::ReadFields(Environment* ev, FW_CReadableStream& stream)
- {
- inherited::ReadFields(ev, stream);
-
- // Read in TPicture fields
- stream >> fPictID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPictSView::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAPictSView::Create(ResType type)
- {
- return new FW_CMAPictSView(type);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAPictSView::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAPictSView::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- // Load the Mac picture resource manually instead of using FW_CPicture API because
- // we don't have the resource file here
- FW_PlatformPict macPictHdl = ::GetPicture(fPictID);
- FW_CPictSView* view;
-
- if (macPictHdl)
- {
- // Must detach the resource manually because we loaded it manually
- ::DetachResource((Handle)macPictHdl);
-
- // Create the FW_CPictSView view
- view = FW_NEW(FW_CPictSView, (ev, superview, fBounds, fIdentifier,
- FW_CPicture(macPictHdl)));
- }
- else
- {
- // If the picture cannot be loaded here we create a FW_CPictSView with the same
- // pict ID, the FW_CPictSView class will display an error message
- view = FW_NEW(FW_CPictSView, (ev, superview, fBounds, fIdentifier, fPictID));
- }
- // view->SetBindings(ev, fBindings);
-
- return view;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAUnknownView::FW_CMAUnknownView
- //----------------------------------------------------------------------------------------
- FW_DEFINE_AUTO(FW_CMAUnknownView)
-
- FW_CMAUnknownView::FW_CMAUnknownView(ResType type, FW_CString& name) :
- FW_CMAView(type),
- fName(name)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAUnknownView::Create
- //----------------------------------------------------------------------------------------
-
- FW_CMAObject* FW_CMAUnknownView::Create(ResType type, FW_CString& name)
- {
- return FW_NEW(FW_CMAUnknownView, (type, name));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMAUnknownView::CreateODFView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CMAUnknownView::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
- {
- FW_UNUSED(receiver);
- FW_CUnknownView* view = FW_NEW(FW_CUnknownView, (ev, superview, fIdentifier, fBounds, fName));
- // view->SetBindings(ev, fBindings);
-
- return view;
- }
-
-
-